import { isArray } from '@/utils';

import Vue from 'vue';

import tool from '@/mixins/tooler';

import lcd_engine from '@/lcd.engine';

const { tooler } = lcd_engine;

import store from '@/store';

export default {
    inserted(el, binding, vnode) {
        const value = binding.value;
        if(isArray(value)) {
            const [name, type, params] = value;
            if(tooler[name]) {
                const { icon, label, trigger } = tooler[name];
                new Vue({//NOSONAR
                    el,
                    template: `<a-button type="${type || 'default'}" v-on:${trigger.method}="e => ${trigger.name}({event: e, params: ${params}})"><svg-icon type="${icon}" />${label}</a-button>`,
                    mixins: [tool],
                    store
                }); 
            } else {
                console.warn('未发现已注册的功能，请确认功能是否已经注册成功')
            }
        } else {
            console.error('绑定指令值不正确，需要为字符串')
        }
    },
}